import React, { useEffect, useState, memo, createRef, useMemo } from 'react';
import styles from './index.less';
import { Input, Form, Button } from 'antd';
import IconFont from '@/components/IconFont';
//修改厂商
const VendorEdit = ({ item, updateInfoProps }) => {
  const [isEdit, setIsEdit] = useState(false);
  let formRef = createRef();

  return (
    <div className={styles['vendor']}>
      {isEdit && (
        <Form ref={formRef} initialValues={{ vendor: item.vendor }}>
          <Form.Item name="vendor">
            <Input />
          </Form.Item>
        </Form>
      )}
      {!isEdit && (item.vendor ? item.vendor : '-')}
      <Button
        onClick={() => {
          setIsEdit(!isEdit ? true : false);
          if (isEdit) {
            let result = formRef.current.getFieldsValue();
            updateInfoProps.run({ id: item.id, vendor: result.vendor });
          }
        }}
        htmlType="submit"
        className={!isEdit && styles['no-border']}
      >
        <IconFont type={isEdit ? 'iconbaocun' : 'iconbianji'} />
      </Button>
    </div>
  );
};

export default VendorEdit;
